const parseArgvs = (x, y) => {
    let a = 0, b = 0;
    try {
        a = Number(x);
    } catch (e) {
        throw new Error(`The ${x} should be number type value.`, e)
    }

    try {
        b = Number(y);
    } catch (e) {
        throw new Error(`The ${y} should be number type value.`, e)
    }

    return [a, b];
}

/**
 * 加法
 * @param {number|string} x 
 * @param {number|string} y
 * @returns {number} 
 */
exports.add = (x, y) => {
    [x, y] = parseArgvs(x, y);
    return x + y;
}

/**
 * 减法
 * @param {number|string} x 
 * @param {number|string} y
 * @returns {number} 
 */
exports.sub = (x, y) => {
    [x, y] = parseArgvs(x, y);
    return x - y;
}

/**
 * 乘法
 * @param {number|string} x 
 * @param {number|string} y
 * @returns {number} 
 */
exports.mul = (x, y) => {
    [x, y] = parseArgvs(x, y);
    return x * y;
}


/**
 * 除法
 * @param {number|string} x 
 * @param {number|string} y
 * @returns {number} 
 */
exports.div = (x, y) => {
    [x, y] = parseArgvs(x, y);
    return x / y;
}

/**
 * 求余
 * @param {number|string} x 
 * @param {number|string} y
 * @returns {number} 
 */
exports.mod = (x, y) => {
    [x, y] = parseArgvs(x, y);
    return x % y;
}